﻿/*
 *  Copyright (C) 2010 by Benjamin Nolmans <benjamin.nolmans@gmail.com>
 *  and Barbara Post <postb99@gmail.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

using System.Web.UI;
using OfficeWebUI.Ribbon;
using OsamesFrameworkCore.Messaging;
using OsamesFrameworkCore.Plugins;
using OsamesFrameworkCore.Logging;

namespace HelloWorldPlugin
{
    public class HelloWorldPlugin : AbstractWebPlugin
    {

        #region Attributes      

        //Declaration of all plugin variables

        private HelloWorldCustomControl _hwccMainControl;
        #endregion

        #region Properties

        #endregion

        #region Public Methods
        /// <summary>
        /// Initilize plugin in memory
        /// </summary>
        public override void Initialize()
        {
            Log(LogLevel.Trace, "Initialize");

            _hwccMainControl = new HelloWorldCustomControl {PluginHost = Host, Plugin = this};
            //LoggerService.LogToOutput("[INFO]: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
            
        }

        /// <summary>
        /// Plugin algorithm call.
        /// </summary>
        /// <param name="strMethodName_">Name of function declared in the plugin to execute by reflection</param>
        /// <param name="oParameters_">Function arguments</param>
        public override object Execute(string strMethodName_, object[] oParameters_)
        {
            // TODO remove this method when Execute is fully implemented in AbstractPlugin
            return Hello();
        }

        /// <summary>
        /// Plugin main function.
        /// </summary>
        public object Hello()
        {
            Log(LogLevel.Trace, "Execute");

            WriteMessage();
            // TODO [plugin hello world] set a value to a new member of plugin (data holder, dummy would be a _strData string).

            return null;
        }

        /// <summary>
        /// GetOutput
        /// </summary>
        /// <returns></returns>
        public override Control GetOutput()
        {
            Log(LogLevel.Trace, "GetOutput");

            // TODO [web plugin internals] Create a FillControl(object) method in interface IPluginWebControl.
            // For HelloWorldCustomControl it will expect param to be a string, and then use the string as internal label text.

            _hwccMainControl.InitializeControl();

            // TODO [web plugin internals / plugin hello world] : FillControl(object) is to be called here, right after InitializeControl()

            return _hwccMainControl;
        }

        /// <summary>
        /// Rendering as tab (context).
        /// </summary>
        /// <returns></returns>
        public override RibbonContext GetRibbonContextRendering()
        {
            Log(LogLevel.Trace, "Ribbon");
            RibbonTab rtTab = new RibbonTab { Text = "Hello World ribbon tab lives here !" };
            RibbonContext rcContext = new RibbonContext { ID = "HelloWorldRC" };
            rcContext.Tabs.Add(rtTab);

            return rcContext;
        }

        /// <summary>
        /// Release plugin of memory
        /// </summary>
        public override void Dispose()
        {
            Log(LogLevel.Trace, "Dispose");
        }
        #endregion

        #region Private Method
        void WriteMessage()
        {
            AddMessage(MessageType.Info, "Hello message info", MessageDisplayLocation.StatusBar);
        }
        #endregion
    }
}